package oauth

import (
	"context"
	"fmt"
	"github.com/gin-gonic/gin"
	"inspector/internal/config"
	"inspector/internal/model/do"
	"net/http"
)

func (a *Controller) Callback(c *gin.Context) {

	var rb do.CallbackParams
	if err := c.ShouldBindQuery(&rb); err != nil {
		c.Error(err)
		return
	}
	err := a.srv.ProcessCallback(context.TODO(), rb)
	if err != nil {
		c.Error(err)
		return
	}

	c.Redirect(http.StatusFound, fmt.Sprintf("%s/-/profile/apps/installations/%s", config.Get().GetAtomConfig().BaseUrl, rb.InstallationID))
}
